%% This is a single script file for ODSS purposes.
% Required files:
%  - data showing scaling factors for all features
%  - filters, in case imfilter isn't available.


%% Check and set environment

close all; clear all; clc;
try
    cd('meris');
    cd('../');
    cd('modis');
    cd('../');
    cd('outs');
    cd('../');
catch
    mkdir('meris');
    mkdir('modis');
    mkdir('outs');
end

merisPath = 'meris/';
modisPath = 'modis/';
outputPath = 'outs/';

%% Download new data
if (isunix || ismac)
    system('cd modis; wget --timestamping -nd ftp://orpheus.pfel.noaa.gov/outgoing/dfoley/mbari/canon/modis/; cd ../');
    system('cd meris; wget --timestamping -nd ftp://orpheus.pfel.noaa.gov/outgoing/dfoley/mbari/canon/meris/; cd ../');
else
    error('Cannot fetch new data. Needs to be run on unix-based OS.');
end

%% Get list of all testable data

chlaFiles = dir([modisPath '*chla_*.mat']);
cflhFiles = dir([modisPath '*cflh_*.mat']);
outFiles = dir([outputPath '*.mat']);

for i=1:length(cflhFiles)
   cflhNames{i} = cflhFiles(i).name(1:end-15);
end

outNames = {};
for i=1:length(outFiles)
   outNames{i} = outFiles(i).name(1:end-15);
end

namesToTest = {};
for i=1:length(chlaFiles)
    chlaName = chlaFiles(i).name(1:end-15);
    
    cflhIndex = find(strcmp(chlaName, cflhNames));
    outIndex = find(strcmp(chlaName, outNames));
    
    if (cflhIndex > 0 && outIndex < 0) % FLH exists, CHLA exists, out doesn't exist
        namesToTest{end+1} = chlaName;
    end
end





%% Rescale/preprocess data

%% Apply filters, build data set

%% Rescale to 0-1, using prior ranges

%% Load ML model, classify using this model

%% Save output